package com.fire.communication.web.web;
//阿里云SMS短信服务demo
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.fire.communication.common.base.BaseService;
import com.fire.communication.support.annotaion.Action;
import com.fire.communication.support.annotaion.At;
import com.fire.communication.support.utils.requestutil.HttpRequestUtil;
import com.fire.communication.web.service.CommunicationService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;

/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.0.3</version>
</dependency>
*/
@Action
@RequestMapping(value="aliCommunications")
public class AliCommunicationsController  extends BaseService {

    @Resource
    private CommunicationService communicationService;

    @At(value = "/request", method = RequestMethod.POST)
    public JSONObject request(HttpServletRequest request) throws Exception {
        JSONObject jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());

        if (jsonParam.size() == 0){
            BufferedReader br = request.getReader();
            String str, wholeStr = "";
            while((str = br.readLine()) != null){
                wholeStr += str;
            }
            JSONArray jsonArray = JSONArray.parseArray(wholeStr);
            communicationService.updateStateAliyun(jsonArray,"2");
        }
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("msg", "成功");
        return ret;
    }


}



